<!DOCTYPE html>
<!--
Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
-->
<html>
<head>
	<meta charset="utf-8">
	<title>CKEditor Sample</title>
	<script src="../ckeditor.js"></script>
	<script src="js/sample.js"></script>
	<script src="js/jquery.min.js"></script>
	<script src="../../css/bootstrap.min.css"></script>
	<script src="../../js/config.js"></script>
	<link rel="stylesheet" href="css/samples.css">
	<link rel="stylesheet" href="toolbarconfigurator/lib/codemirror/neo.css">
    <style>

        .content{
            margin: 0 auto;
            width: 800px;
        }
    </style>
</head>
<body>
<header>
<div style="height: 50px;width: 100%;background-image: url(img/top_back.png);">
    &nbsp;&nbsp;&nbsp;&nbsp;<img src="img/logos.png">
</div>
<h1 align="center">普通新闻发布</h1>
</header>

<main style="  background-color: #f9f9f9;">

<div class="content">
    <form class="form-horizontal" method="post" action="http://localhost:8099/news" enctype="multipart/form-data">
        <div class="form-group">

            <div class="col-sm-10">
                <label for="title" class="col-sm-2">标题:</label>
                <input type="text" name="title" id="title" style="width: 700px"/>
            </div>
        </div>
        <br/>
        <div class="form-group">

            <div class="col-sm-10">
                <label for="author" class="control-label">作者:</label>
                <input type="text" name="author" id="author"/>
            </div>
        </div>
        <br/>
        <div class="form-group">
            <table>
                <tr>
                    <td><label for="introduce" >简介:</label></td>
                    <td> <textarea name="introduce" rows="3" id="introduce" style="width: 700px;"></textarea></td>
                </tr>
            </table>



        </div>
        <br/>

        <!--<div class="form-group">-->
            <!--<div class="col-sm-10">-->
                <!--<label for="introduceImg" class="control-label">展示图片:</label>-->
                <!--<input type="file" name="introduceImg" id="introduceImg">-->
            <!--</div>-->
        <!--</div>-->

        <br/>
        <textarea name="editor" id="editor"></textarea>
        <input type="hidden" name="filetype" id="filetype">
        <br/>
        <div class="form-group">

            <div class="col-sm-10">
                <label for="newsclass" class="control-label">分类:</label>
                <select class="form-control" id="newsclass" name="newsclass">

                </select>

                <select class="form-control" id="secondclass" name="secondclass">

                </select>

                <input type="hidden" name="classname" id="classname">
            </div>
        </div>
        <br/>
        <div class="form-group">
            <input type="submit" name="发布" value="发布" onclick="change()">
        </div>



    </form>

</div>
</main>

<footer class="footer-a grid-container">

</footer>

<script>
    var select = $('#newsclass');
    var secondclass = $('#secondclass');
	initSample();
    initclass();
    initsecondclass();
    select.on('change',function () {
        initsecondclass();
    });


    function initclass(){

        $.ajax({
            type:'GET',
            url:host+"/news/class/parent?parentId=0",

            async:false,
            success:function (data) {
                if(data.code == 1){
                    var temp = '';
                    select.empty();
                    $.each(data.list,function (i, item) {
                        temp+='<option value="'+item.id+'">'+item.name+'</option>';
                    });
                    select.append(temp);
                }
            },
            error: function(XMLHttpRequest){
                alert( "请求错误 " + XMLHttpRequest.responseText);
            }
        });

    }

    function initsecondclass() {

        if (select.val()){
            $.ajax({
                type:'GET',
                url:host+"/news/class/parent?parentId="+select.val(),

                async:false,
                success:function (data) {
                    if(data.code == 1){
                        var temp = '';
                        secondclass.empty();
                        $.each(data.list,function (i, item) {
                            temp+='<option value="'+item.id+'">'+item.name+'</option>';
                        });
                        secondclass.append(temp);
                    }
                },
                error: function(XMLHttpRequest){
                    alert( "请求错误 " + XMLHttpRequest.responseText);
                }
            });
        }
    }

    function change(){
        $('#classname').val($("#secondclass").find("option:selected").text());
        var  type = document.getElementById("introduceImg").value.split('.');
        document.getElementById("filetype").value = type[type.length-1];
    }
</script>

</body>
</html>
